public class Solution {
    public int pivotIndex(int[] nums) {
        int a = 0;
        int b = 0;
        for (int i = 0; i < nums.length; i++) {
            if (left(i,nums) == right(i,nums)){
                a = 1;
                b = i;
                break;
            }
        }
        if (a == 0){
            return -1;
        }
        return b;
    }
    public int left(int x,int[] nums) {
        int sum = 0;
        for (int i = 0; i < x; i++) {
            sum += nums[i];
        }
        return sum;
    }
    public int right(int x,int[] nums) {
        int sum = 0;
        for (int i = x+1; i < nums.length; i++) {
            sum += nums[i];
        }
        return sum;
    }
}
